home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-03 | 29.6 KB | 1,038 lines | [TEXT/MPS ] |
- //----------------------------------------------------------------------------------------
- // UCommand.cp
- // Copyright © 1985-96 by Apple Computer, Inc. All rights reserved.
- //----------------------------------------------------------------------------------------
-
- #ifndef __UCOMMAND__
- #include "UCommand.h"
- #endif
-
- // MacApp
-
- #ifndef __UAPPLEEVENTS__
- #include "UAppleEvents.h"
- #endif
-
- #ifndef __UCLIPBOARDMGR__
- #include "UClipboardMgr.h"
- #endif
-
- #ifndef __UCOMMANDHANDLER__
- #include "UCommandHandler.h"
- #endif
-
- #ifndef __UCOREERRORMGR__
- #include "UCoreErrorMgr.h"
- #endif
-
- #ifndef __UCOREGLOBALS__
- #include "UCoreGlobals.h"
- #endif
-
- #ifndef __UCOREUTILITIES__
- #include "UCoreUtilities.h"
- #endif
-
- #ifndef __UDEBUG__
- #include "UDebug.h"
- #endif
-
- #ifndef __UDEPENDENCIES__
- #include "UDependencies.h"
- #endif
-
- #ifndef __UDISPATCHER__
- #include "UDispatcher.h"
- #endif
-
- #ifndef __UDOCUMENT__
- #include "UDocument.h"
- #endif
-
- // #ifndef __UERRORMGR__
- // #include "UErrorMgr.h"
- // #endif
-
- #ifndef __UGEOMETRY__
- #include "UGeometry.h"
- #endif
-
- #ifndef __UMACAPPGLOBALS__
- #include "UMacAppGlobals.h"
- #endif
-
- #ifndef __UMACAPPUTILITIES__
- #include "UMacAppUtilities.h"
- #endif
-
- #ifndef __UMEMORY__
- #include "UMemory.h"
- #endif
-
- #ifndef __USCRIPTING__
- #include "UScripting.h"
- #endif
-
- // #ifndef __USCROLLER__
- // #include "UScroller.h"
- // #endif
-
- #ifndef __USEGMENTS__
- #include "USegments.h"
- #endif
-
- #ifndef __UVIEW__
- #include "UView.h"
- #endif
-
- // #ifndef __UWINDOW__
- // #include "UWindow.h"
- // #endif
-
- // Toolbox
-
- #ifndef __LOWMEM__
- #include <LowMem.h>
- #endif
-
- #ifndef __OSEVENTS__
- #include <OSEvents.h>
- #endif
-
- // ANSI
-
- #ifndef __STDIO__
- #include <stdio.h>
- #endif
-
- #ifndef __STDLIB__
- #include <stdlib.h>
- #endif
-
- //========================================================================================
- // Global Functions
- //========================================================================================
- #pragma segment MACommandRes
-
- TCommand* CommitACommand(TCommand *aCommand)
- {
- if (aCommand)
- {
- #if qDebug
- if (!VerboseIsObject(aCommand))
- {
- ProgramBreak("In CommitCompletedCommand: Not handed a valid object");
- return NULL;
- }
- #endif
- // if (aCommand->fCommandDone)
- // aCommand->Commit();
-
- aCommand->Completed();
-
- if (aCommand->ShouldFreeOnCompletion())
- FreeIfObject(aCommand);
- }
-
- return NULL;
- }
-
- //========================================================================================
- // CLASS TCommand
- //========================================================================================
- #undef Inherited
- #define Inherited TEvent
-
- #pragma segment MACommandNonRes
- MA_DEFINE_CLASS_M1(TCommand, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TCommand constructor
- //----------------------------------------------------------------------------------------
- #pragma segment MACommandRes
-
- TCommand::TCommand()
- : fObjectToNotify(NULL),
- fContext(NULL),
- // fLinkedCommand(NULL),
- // fLinkIdentity(kNotLinked),
- fCommandDone(FALSE),
- fCanUndo(TRUE),
- fCausesChange(TRUE),
- fChangesClipboard(FALSE),
- fClipboardView(NULL),
- fUndoClipboardView(NULL),
- fUndoClipboardViewContext(NULL),
- fFreeOnCompletion(TRUE), // command will be freed after DoIt or Commit
- fRecurring(FALSE), // Command is a one-shot deal
- fReadyToExecute(TRUE), // Always executable by default
- fValidationError(noErr), // Hasn't failed yet...
- fUseAppleEvent(FALSE)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TCommand::ICommand:
- //----------------------------------------------------------------------------------------
- #pragma segment MACommandRes
-
- void TCommand::ICommand(CommandNumber itsCommandNumber,
- TCommandHandler* itsContext, // Typically a document or a document-less view
- Boolean canUndo,
- Boolean causesChange,
- TObject* objectToNotify) // Typically the context
- {
- TCommandHandler* theContext = itsContext;
- if (itsContext == NULL)
- theContext = gDispatcher;
-
- this->IEvent(itsCommandNumber, NULL, theContext);
-
- fIdentifier = itsCommandNumber;
- fCanUndo = canUndo;
- fCausesChange = causesChange;
- fObjectToNotify = objectToNotify;
- fContext = theContext;
- }
-
- //----------------------------------------------------------------------------------------
- // TCommand::Free:
- //----------------------------------------------------------------------------------------
- #pragma segment MADoCommand
-
- TCommand::~TCommand()
- {
- if (fChangesClipboard)
- {
- this->AbandonClipboardView();
- this->AbandonUndoClipboardView();
- }
-
- // If this command is in the action history, it should
- // be freed only through the undo handler, so the
- // action history can be cleaned up before the command is freed.
-
- // this->LinkToSecondary(NULL); // clear the reference to this command in its linked cmd
- }
-
- //----------------------------------------------------------------------------------------
- // TCommand::AbandonClipboardView
- //----------------------------------------------------------------------------------------
- #pragma segment MADoCommand
-
- void TCommand::AbandonClipboardView() // override
- {
- // fClipboardView is owned by this command, which created it, unless it
- // is the current clipboard, in which case it is owned by gClipboardMgr.
-
- // Note:: TView::FreeFromClipboard calls gClipboardMgr->Changed
- // so that if another command has a reference to this fClipboardView
- // in its fUndoClipboardView field, it can NULL it.
-
- if (fClipboardView)
- {
- if (fClipboardView == gClipboardMgr->fClipView)
- gClipboardMgr->fClipContext = NULL;
- else
- {
- fClipboardView->FreeFromClipboard();
- fClipboardView = NULL;
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TCommand::AbandonClipboardView
- //----------------------------------------------------------------------------------------
- #pragma segment MADoCommand
-
- void TCommand::AbandonUndoClipboardView()
- {
- // Note:: TView::FreeFromClipboard calls gClipboardMgr->Changed
- // so that if another command has a reference to this fUndoClipboardView
- // in its fClipboardView field, it can NULL it.
-
- if (fUndoClipboardView
- && (fUndoClipboardView != gClipboardMgr->fClipView)
- && ((fUndoClipboardViewContext == NULL) || (fUndoClipboardViewContext == fContext)) )
- {
- fUndoClipboardView->FreeFromClipboard();
- fUndoClipboardView = NULL;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TCommand::PrepareForUndoRedo:
- //----------------------------------------------------------------------------------------
- #pragma segment MADoCommand
-
- void TCommand::PrepareForUndoRedo()
- {
- if (fContext)
- fContext->PrepareForUndoRedo(this);
- }
-
- //----------------------------------------------------------------------------------------
- // TCommand::FinishUndoRedo:
- //----------------------------------------------------------------------------------------
- #pragma segment MADoCommand
-
- void TCommand::FinishUndoRedo()
- {
- if (fChangesClipboard)
- UndoRedoClipboard();
-
- fCommandDone = !fCommandDone;
- DoNotification();
- }
-
- //----------------------------------------------------------------------------------------
- // TCommand::RevealUndoRedo:
- //----------------------------------------------------------------------------------------
- #pragma segment MADoCommand
-
- void TCommand::RevealUndoRedo()
- {
- if (fContext)
- fContext->RevealUndoRedo(this);
- }
-
- //----------------------------------------------------------------------------------------
- // TCommand::Commit:
- //----------------------------------------------------------------------------------------
- // #pragma segment MADoCommand
-
- // void TCommand::Commit()
- // {
- // }
-
- //----------------------------------------------------------------------------------------
- // TCommand::Completed:
- //----------------------------------------------------------------------------------------
- #pragma segment MADoCommand
-
- void TCommand::Completed()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TCommand::DoIt:
- //----------------------------------------------------------------------------------------
- #pragma segment MADoCommand
-
- void TCommand::DoIt()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TCommand::GetChangeID:
- //----------------------------------------------------------------------------------------
- #pragma segment MACommandRes
-
- ChangeID TCommand::GetChangeID()
- {
- return fIdentifier;
- }
-
- //----------------------------------------------------------------------------------------
- // TCommand::CanBeUndone:
- //----------------------------------------------------------------------------------------
- #pragma segment MACommandRes
-
- Boolean TCommand::CanBeUndone()
- {
- return fCanUndo;
- }
-
- //----------------------------------------------------------------------------------------
- // TCommand::IsReadyToExecute:
- //----------------------------------------------------------------------------------------
- #pragma segment MACommandRes
-
- Boolean TCommand::IsReadyToExecute() // override
- {
- return fReadyToExecute;
- }
-
- //----------------------------------------------------------------------------------------
- // TCommand::IsRecurring:
- //----------------------------------------------------------------------------------------
- #pragma segment MACommandRes
-
- Boolean TCommand::IsRecurring() // override
- {
- return fRecurring;
- }
-
- //----------------------------------------------------------------------------------------
- // TCommand::WillCauseChange:
- //----------------------------------------------------------------------------------------
- #pragma segment MACommandRes
-
- Boolean TCommand::WillCauseChange()
- {
- return fCausesChange;
- }
-
- //----------------------------------------------------------------------------------------
- // TCommand::MakeAppleEvent:
- //----------------------------------------------------------------------------------------
- #pragma segment MACommandRes
-
- TAppleEvent* TCommand::MakeAppleEvent()
- {
- return NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // TCommand::DoNotification:
- //----------------------------------------------------------------------------------------
- #pragma segment MACommandRes
-
- void TCommand::DoNotification()
- {
- // Notify the proper object that a change has occurred
- if (this->WillCauseChange() && fObjectToNotify)
- {
- ChangeID theChange;
- if (fCommandDone)
- theChange = this->GetChangeID();
- else
- theChange = cUndo;
- fObjectToNotify->Changed(theChange, this);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TCommand::SetupDependencies:
- //----------------------------------------------------------------------------------------
- #pragma segment MACommandRes
-
- void TCommand::SetupDependencies()
- {
- if (this->CanBeUndone())
- {
- fContext->AddDependent(this);
- if (fChangesClipboard || (fIdentifier == cPaste))
- gClipboardMgr->AddDependent(this);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TCommand::DoUpdate:
- //----------------------------------------------------------------------------------------
- #pragma segment MACommandRes
-
- void TCommand::DoUpdate(ChangeID theChange,
- TObject* changedObject,
- TObject* changedBy,
- TDependencySpace* /* dependencySpace */) // override
- {
- switch (theChange)
- {
- case mClipViewChanged:
- // This code appears to be there to support Paste commands
- // whose RedoIt methods go back to the clipboard document for the
- // data to paste. *** This won't work with multiple undo. ***
- // From now on, commands need to save all the data needed for
- // their UndoIt and RedoIt methods.
-
- // if ((changedObject == gClipboardMgr) &&
- // (fIdentifier == cPaste))
- // fContext->CommitLastCommand();
- break;
-
- case mFreeClipboardView:
- if (changedObject == gClipboardMgr)
- if (changedBy == fUndoClipboardView)
- {
- fUndoClipboardView = NULL;
- fUndoClipboardViewContext = NULL;
- }
- else if (changedBy == fClipboardView)
- fClipboardView = NULL;
- break;
-
- case mClosed:
- if ((changedObject == fContext)
- /* || (theChange == mAboutToLoseControl) */
- || (theChange == mScrapChanged))
- fContext->CommitLastCommand();
- break;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TCommand::RedoIt:
- //----------------------------------------------------------------------------------------
- #pragma segment MADoCommand
-
- void TCommand::RedoIt()
- {
- this->DoIt();
- }
-
- //----------------------------------------------------------------------------------------
- // TCommand::ShouldFreeOnCompletion:
- //----------------------------------------------------------------------------------------
- #pragma segment MACommandRes
-
- Boolean TCommand::ShouldFreeOnCompletion()
- {
- return (!fRecurring && fFreeOnCompletion);
- }
-
- //----------------------------------------------------------------------------------------
- // TCommand::UndoIt:
- //----------------------------------------------------------------------------------------
- #pragma segment MADoCommand
-
- void TCommand::UndoIt()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TCommand::Process:
- //----------------------------------------------------------------------------------------
- #pragma segment MACommandRes
-
- void TCommand::Process()
- {
- if (fContext)
- fContext->PerformCommand(this);
- }
-
- //----------------------------------------------------------------------------------------
- // TCommand::NeedsToUnloadAllSegments:
- //----------------------------------------------------------------------------------------
- #pragma segment MACommandRes
-
- Boolean TCommand::NeedsToUnloadAllSegments()
- {
- return TRUE;
- }
-
- //----------------------------------------------------------------------------------------
- // TCommand::LinkToSecondary:
- //----------------------------------------------------------------------------------------
- #pragma segment MACommandRes
-
- //----------------------------------------------------------------------------------------
- // TCommand::SetValidationError:
- //----------------------------------------------------------------------------------------
- #pragma segment MACommandRes
-
- void TCommand::SetValidationError(OSErr validationError)
- {
- fValidationError = validationError;
- // if (fLinkedCommand)
- // fLinkedCommand->fValidationError = validationError;
- }
-
- //----------------------------------------------------------------------------------------
- // TCommand::Abort:
- //----------------------------------------------------------------------------------------
- #pragma segment MACommandRes
-
- void TCommand::Abort()
- {
- // Try to remove the command in case it is no longer recurring.
- gDispatcher->RemoveEvent(this);
-
- if ((gClipboardMgr->fClipView != NULL) &&
- (gClipboardMgr->fClipView == fClipboardView))
- {
- gClipboardMgr->SetClipView(fUndoClipboardView, fUndoClipboardViewContext);
- fUndoClipboardView = NULL;
- }
-
- if (fCommandDone && CanBeUndone())
- {
- UndoIt();
- if (fChangesClipboard)
- UndoRedoClipboard();
- fCommandDone = FALSE;
- DoNotification();
- }
-
- Completed();
- }
-
- //----------------------------------------------------------------------------------------
- // TCommand::ClaimClipboard:
- //----------------------------------------------------------------------------------------
- #pragma segment MACommandRes
-
- void TCommand::ClaimClipboard(TView* clipboardView)
- {
- // For RedoIt only
- this->AbandonUndoClipboardView();
-
- fUndoClipboardView = gClipboardMgr->fClipView; // Copy current clipboard contents to the
- // Undo side
- fUndoClipboardViewContext = fContext; // gClipboardMgr->fClipContext;
- if (clipboardView)
- {
- gClipboardMgr->SetClipView(clipboardView, fContext); // Will install it as fClipView
- fClipboardView = clipboardView;
- }
- #if qDebugMsg
- else
- ProgramBreak("Claiming clipboard with NULL view");
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // TCommand::UndoRedoClipboard:
- //----------------------------------------------------------------------------------------
- #pragma segment MACommandRes
-
- void TCommand::UndoRedoClipboard()
- {
- if (fCommandDone)
- {
- // Undoing
- if (fUndoClipboardView && (gClipboardMgr->fClipContext == fContext))
- {
- gClipboardMgr->SetClipView(fUndoClipboardView, fUndoClipboardViewContext);
- }
- }
- else if (fValidationError == noErr)
- {
- // Redoing
- this->ClaimClipboard(fClipboardView);
- }
- }
-
- //========================================================================================
- // CLASS TAppleCommand
- //========================================================================================
- #undef Inherited
- #define Inherited TCommand
-
- #pragma segment MACommandNonRes
- MA_DEFINE_CLASS_M1(TAppleCommand, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TAppleCommand constructor
- //----------------------------------------------------------------------------------------
- #pragma segment MACommandRes
-
- TAppleCommand::TAppleCommand() :
- fMessage(NULL),
- fReply(NULL)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TAppleCommand::IAppleCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment MACommandRes
-
- void TAppleCommand::IAppleCommand(CommandNumber itsCommandNumber,
- TCommandHandler* itsContext,
- Boolean canUndo,
- Boolean causesChange,
- TObject* objectToNotify)
- {
- this->ICommand(itsCommandNumber, itsContext, canUndo, causesChange, objectToNotify);
- }
-
- //----------------------------------------------------------------------------------------
- // TAppleCommand::IAppleCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment MACommandRes
-
- void TAppleCommand::IAppleCommand(CommandNumber itsCommandNumber,
- TCommandHandler* itsContext,
- Boolean canUndo,
- Boolean causesChange,
- TObject* objectToNotify,
- TAppleEvent* message,
- TAppleEvent* reply)
- {
- this->ICommand(itsCommandNumber, itsContext, canUndo,
- causesChange, objectToNotify);
- fMessage = message;
- fReply = reply;
- }
-
- //----------------------------------------------------------------------------------------
- // TAppleCommand::Free:
- //----------------------------------------------------------------------------------------
- #pragma segment MADoCommand
-
- TAppleCommand::~TAppleCommand()
- {
- this->FreeTheMessage(); // Properly free the events by resuming if necessary
- }
-
- //----------------------------------------------------------------------------------------
- // TAppleCommand::FreeTheMessage:
- //----------------------------------------------------------------------------------------
- #pragma segment MADoCommand
-
- void TAppleCommand::FreeTheMessage()
- {
- fMessage = (TAppleEvent *)FreeIfObject(fMessage);
- fReply = (TAppleEvent *)FreeIfObject(fReply);
- }
-
- //========================================================================================
- // CLASS TServerCommand
- //========================================================================================
- #undef Inherited
- #define Inherited TAppleCommand
-
- #pragma segment MACommandNonRes
- MA_DEFINE_CLASS_M1(TServerCommand, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TServerCommand constructor
- //----------------------------------------------------------------------------------------
- #pragma segment MACommandRes
-
- TServerCommand::TServerCommand() :
- fRequiresUserInteraction(FALSE),
- fSuspendTheEvent(FALSE),
- fReplySent(FALSE)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TServerCommand destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TServerCommand::~TServerCommand()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TServerCommand::IServerCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment MACommandRes
-
- void TServerCommand::IServerCommand(CommandNumber itsCommandNumber,
- TCommandHandler* itsContext,
- Boolean canUndo,
- Boolean causesChange,
- TObject* objectToNotify)
- {
- this->IAppleCommand(itsCommandNumber, itsContext, canUndo, causesChange, objectToNotify);
- }
-
- //----------------------------------------------------------------------------------------
- // TServerCommand::IServerCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment MACommandRes
-
- void TServerCommand::IServerCommand(CommandNumber itsCommandNumber,
- TCommandHandler* itsContext,
- Boolean canUndo,
- Boolean causesChange,
- TObject* objectToNotify,
- const AppleEvent& itsMessage,
- const AppleEvent& itsReply)
- {
- this->IAppleCommand(itsCommandNumber, itsContext, canUndo, causesChange, objectToNotify);
-
- FailInfo fi;
- Try(fi)
- {
- // Inform the AppleEvent manager that this event will be processed asynchronously.
- // Any reply that needs to be returned will be returned in TServerCommand::Completed().
- if (fSuspendTheEvent)
- AESuspendTheCurrentEvent(&itsMessage);
-
- TAppleEvent* aMessage = new TAppleEvent;
- aMessage->InitializeFromMessage(itsMessage, FALSE);
- fMessage = aMessage;
-
- TAppleEvent* aReply = new TAppleEvent;
- aReply->InitializeFromMessage(itsReply, FALSE);
- fReply = aReply;
-
- fi.Success();
- }
- else // Recover
- {
- // TApplication::DispatchAppleEvent takes care of canceling the suspension of
- // the message in case of failure so all we worry about here is freeing the command
- this->Free();
-
- fi.ReSignal();
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TServerCommand::IServerCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment MACommandRes
-
- void TServerCommand::IServerCommand(CommandNumber itsCommandNumber,
- TCommandHandler* itsContext,
- Boolean canUndo,
- Boolean causesChange,
- TObject* objectToNotify,
- TAppleEvent* itsMessage,
- TAppleEvent* itsReply)
- {
- this->IAppleCommand(itsCommandNumber, itsContext, canUndo, causesChange, objectToNotify);
-
- FailInfo fi;
- Try(fi)
- {
- // Inform the AppleEvent manager that this event will be processed asynchronously.
- // Any reply that needs to be returned will be returned in TServerCommand::Completed().
- if (fSuspendTheEvent)
- AESuspendTheCurrentEvent(&itsMessage->fMessage);
-
- fMessage = itsMessage;
- fReply = itsReply;
-
- fi.Success();
- }
- else // Recover
- {
- // TApplication::DispatchAppleEvent takes care of canceling the suspension of
- // the message in case of failure so all we worry about here is freeing the command
- this->Free();
-
- fi.ReSignal();
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TServerCommand::Completed:
- //----------------------------------------------------------------------------------------
- #pragma segment MADoCommand
-
- void TServerCommand::Completed() // override
- {
- if (fMessage && fReply)
- this->ResumeAndFreeMessage();
- }
-
- //----------------------------------------------------------------------------------------
- // TServerCommand::Process:
- //----------------------------------------------------------------------------------------
- #pragma segment MACommandRes
-
- void TServerCommand::Process()
- {
- if (fRequiresUserInteraction)
- {
- FailInfo fi1;
- Try(fi1)
- {
- FailOSErr(MAInteractWithUser());
- fi1.Success();
- }
- else
- {
- this->SetValidationError(fi1.error);
- fi1.ReSignal();
- }
- }
- FailInfo fi2;
- Try(fi2)
- {
- Inherited::Process();
- fi2.Success();
- }
- else
- {
- // If an error arose and a reply was sent then ignore the error
- // at this point.
- if (!fReplySent)
- {
- if (fi2.error == userCanceledErr)
- FailNewMessage(noErr, fi2.message, messageCancelled);
- fi2.ReSignal();
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TServerCommand::ResumeAndFreeMessage:
- //----------------------------------------------------------------------------------------
- #pragma segment MACommandRes
-
- void TServerCommand::ResumeAndFreeMessage()
- {
- // If the event has been suspended then resume it and free the message.
- if (fSuspendTheEvent)
- {
- AppleEvent theMessage = fMessage->fMessage;
- AppleEvent theReply = fReply->fMessage;
-
- // Inform the AppleEvent manager that we are through processing the event. If an error
- // has occurred the default reply will contain the error number and error string.
- AEEventHandlerUPP dispatcher = kAENoDispatch;
-
- AEResumeTheCurrentEvent(&theMessage, &theReply, dispatcher, 0);
- fReplySent = TRUE;
- }
- // Free the message and its reply since they are no longer valid
- this->FreeTheMessage();
- }
-
- //----------------------------------------------------------------------------------------
- // TServerCommand::SetValidationError:
- //----------------------------------------------------------------------------------------
- #pragma segment MACommandRes
-
- void TServerCommand::SetValidationError(OSErr error)
- {
- // The finder passes a null reply with required events
- // so don't try to stuff any info into the reply
- if (fReply && fReply->fMessage.descriptorType != typeNull)
- fReply->WriteOSError(error);
- Inherited::SetValidationError(error);
- }
-
- //========================================================================================
- // CLASS TClientCommand
- //========================================================================================
- #undef Inherited
- #define Inherited TAppleCommand
-
- #pragma segment MACommandNonRes
- MA_DEFINE_CLASS_M1(TClientCommand, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TClientCommand constructor
- //----------------------------------------------------------------------------------------
- #pragma segment MACommandRes
-
- TClientCommand::TClientCommand() :
- fMessageSent(FALSE)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TClientCommand destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TClientCommand::~TClientCommand()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TClientCommand::IClientCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment MACommandRes
-
- void TClientCommand::IClientCommand(CommandNumber itsCommandNumber,
- TCommandHandler* itsContext,
- Boolean canUndo,
- Boolean causesChange,
- TObject* objectToNotify,
- TAppleEvent* theMessage)
- {
- this->IAppleCommand(itsCommandNumber, itsContext, canUndo, causesChange, objectToNotify);
- this->fMessage = theMessage;
- }
-
- //----------------------------------------------------------------------------------------
- // TClientCommand::GetReturnID:
- //----------------------------------------------------------------------------------------
- #pragma segment MACommandRes
-
- long TClientCommand::GetReturnID()
- {
- if (fMessage)
- return fMessage->GetReturnID();
- else
- return 0;
- }
-
- //----------------------------------------------------------------------------------------
- // TClientCommand::IsReadyToPost:
- //----------------------------------------------------------------------------------------
- #pragma segment MACommandRes
-
- Boolean TClientCommand::IsReadyToPost() // override
- {
- Boolean ready = TRUE;
-
- if (fMessage)
- {
- if (!fMessageSent)
- {
- if ((fMessage->GetSendingMode() & kAEReplyModeMask) == kAEWaitReply)
- {
- TAppleEvent* theReply = NULL;
-
- theReply = this->SendMessage();
- this->ProcessReply(theReply);
- }
- else if ((fMessage->GetSendingMode() & kAEReplyModeMask) == kAEQueueReply)
- {
- this->SendMessage(); // No reply will be returned
- TOSADispatcher::fgDispatcher->PostPendingReplyCommand(this);
- ready = FALSE;
- }
- }
- else if (((fMessage->GetSendingMode() & kAEReplyModeMask) == kAEQueueReply) && (fReply == NULL))
- ready = FALSE; // Even though the message has been sent we still
- // haven't received our reply so don't post it yet.
- }
- return ready;
- }
-
- //----------------------------------------------------------------------------------------
- // TClientCommand::SendMessage:
- //----------------------------------------------------------------------------------------
- #pragma segment MACommandRes
-
- TAppleEvent* TClientCommand::SendMessage()
- {
- if (fMessage)
- {
- fMessageSent = TRUE;
- return fMessage->Send();
- }
- else
- return NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // TClientCommand::ProcessReply:
- //----------------------------------------------------------------------------------------
- #pragma segment MACommandRes
-
- void TClientCommand::ProcessReply(TAppleEvent* theReply)
- {
- fReply = theReply;
-
- // Check for errors in the reply.
- long errorNumber;
- CStr255 errorString;
- theReply->ReadError(errorNumber, errorString);
-
- if ((errorNumber != noErr) || !errorString.IsEmpty())
- {
- if (gDispatcher)
- gDispatcher->ReportReplyError(fIdentifier, (OSErr)errorNumber, errorString);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TClientCommand::DoIt:
- //----------------------------------------------------------------------------------------
- #pragma segment MADoCommand
-
- void TClientCommand::DoIt() // override
- {
- if (fMessage && ((fMessage->GetSendingMode() & kAEReplyModeMask) == kAENoReply))
- this->SendMessage();
- }
-
- //----------------------------------------------------------------------------------------
- // End of UCommand.cp
-
- #pragma segment Inline
-